package com.swlz.service.impl;

import java.sql.SQLException;

import com.swlz.dao.ArticleTypeDAO;
import com.swlz.entity.ArticleType;
import com.swlz.exception.CodeException;
import com.swlz.service.ArticleTypeService;
import com.swlz.vo.PageVO;

/**
 * <pre>
 * 业务逻辑接口具体实现类
 * 文章类别
 * ClassName : com.swlz.service.impl.ArticleTypeServiceImpl
 * Author : swlz
 * E-Mail : 2233875735@qq.com
 * Date : 2020-07-01 22:49:49
 * Version : 1.0
 * Copyright 2020 swlz.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes
 * </pre>
 **/
public class ArticleTypeServiceImpl implements ArticleTypeService {
	
	private ArticleTypeDAO articleTypeDAO = new ArticleTypeDAO();

	@Override
	public int add(ArticleType articleType) throws CodeException {
		try {
			return articleTypeDAO.insertSelective(articleType);
		} catch (SQLException e) {
			throw new CodeException(500, "添加文章类别错误",e);
		}
	}

	@Override
	public int update(ArticleType articleType) throws CodeException {
		try {
			return articleTypeDAO.updateSelective(articleType);
		} catch (SQLException e) {
			throw new CodeException(501, "修改文章类别错误",e);
		}
	}

	@Override
	public int delete(Long articleTypeId) throws CodeException {
		try {
			return articleTypeDAO.deleteById(articleTypeId);
		} catch (SQLException e) {
			throw new CodeException(502, "删除文章类别错误",e);
		}
	}

	@Override
	public ArticleType get(Long articleTypeId) throws CodeException {
		try {
			return articleTypeDAO.selectById(articleTypeId);
		} catch (SQLException e) {
			throw new CodeException(503, "获取文章类别失败",e);
		}
	}

	@Override
	public PageVO<ArticleType> page(ArticleType articleType, Integer current, Integer rowMax) throws CodeException {
		try {
			long total = articleTypeDAO.countByModel(articleType);
			PageVO<ArticleType> page = new PageVO<>(total, current, rowMax);
			return page.setList(articleTypeDAO.selectByModel(articleType, page.getOffset(), page.getRowMax()));
		} catch (SQLException e) {
			throw new CodeException(504, "获取文章类别分页数据失败",e);
		}
	}


}
